package com.superman.czx.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;

/**
 * Created with IDEA
 * author:zhiXiang-Chen
 * Date:2022/4/9
 * Time:15:45
 */

@Controller
public class PdfController {

    @ResponseBody
    @GetMapping("/preview2")
    public void findPdf(HttpServletResponse response, HttpServletRequest request) throws IOException {
        response.setContentType("application/pdf");
        FileInputStream in = new FileInputStream(new File("D:\\222.pdf"));

        ServletInputStream inputStream = request.getInputStream();

        OutputStream out = response.getOutputStream();
        byte[] b = new byte[512];
        while ((in.read(b))!=-1) {
            out.write(b);
        }
        out.flush();
        in.close();
        out.close();
    }
}
